document.addEventListener('plusready', function() {
	const OldOpenUrl = plus.storage.getItem("OpenUrl");
	
	if(OldOpenUrl) plus.webview.open(OldOpenUrl);
	
	/**
	 * @description: 根据服务器加载控制界面
	 * @author: 王琛
	 * @Date: 2025-09-09 11:43:27
	 * @param {*}
	 * @return {*}
	 */
	
	let AlertTimeOut = null;
	
	function LodingIp() {
		try {
			const _SeverIp = $("#ServerIp").val()
			
			const _SeverPort = $("#ServerPort").val() || "3001"
			
			if (!_SeverIp.trim()) throw new Error("Ip不能为空")
	
			const regex = /^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
	
			const IsIp = regex.test(_SeverIp);
	
			if (!IsIp) throw new Error("Ip填写不正确")
			
			const OpenUrl = `http://${ _SeverIp }:${_SeverPort}/index.html`
			
			plus.webview.open(OpenUrl);
			
			plus.storage.setItem("OpenUrl",OpenUrl);
	
		} catch (e) {
			
			clearTimeout(AlertTimeOut)
	
			$(".ErrorAlertBox").html(e.message).removeClass("Hidden")
	
			AlertTimeOut = setTimeout(() => {
				$(".ErrorAlertBox").addClass("Hidden")
			}, 3000)
	
		}

	}
	
	$(".LodingBtn").click(LodingIp);
})
